<?php
/**
 * LICENSE
 * 
 * [license information]
 * 
 * @category   BKPay
 * @copyright  Copyright (c) 2011 bkpay.vn
 * @license    http://license.bkpay.vn
 * @version    v 1.0 2011-09-19
 * @author	   hoaihuong@9webdesigns.com, s50702790@gmail.com
 */

/*
 * 	To set soap Header
 *  $wsse_header = new BKPay_Soap_Header($username, $password,$token);
	$client = new SoapClient('{...}', array("trace" => 1, "exception" => 0));
	$client->__setSoapHeaders(array($wsse_header));
 */
class BKPay_Soap_Header extends SoapHeader {

	private $wss_link = 'https://bkpay.local/transaction/server/api';
	
	function __construct($api, $code, $nslink = null){
	
		if($nslink){
			$this->wss_link = $nslink;
		}
		/*
		 * Create UserNameToken inclue Username and password in xml
		 */
//		$auth = new stdClass();
//		$auth->UserName = new SoapVar($username,XSD_STRING,NULL,$this->wss_link,"Username","wsse:Username");
//		$auth->Password = new SoapVar($password,XSD_STRING,NULL,$this->wss_link,"Password","wsse:Password");
//		
//		$UsernameToken = new stdClass();
//		$UsernameToken->UsernameToken = new SoapVar($auth,SOAP_ENC_OBJECT,NULL,$this->wss_link
//														,"UsernameToken","wsse:UsernameToken");
//		$UsernameToken->Token = new SoapVar($Token,XSD_STRING,NULL,$this->wss_link,"Token","wsse:Token");
//		
//		$security = new SoapVar(
//        		new SoapVar($UsernameToken, SOAP_ENC_OBJECT, NULL, $this->wss_link, 'Security',"wsse:Security"),
//        SOAP_ENC_OBJECT, NULL, $this->wss_link, 'SoapSecurity', "wsse:SoapSecurity");
        
        $token = new stdClass();
		$token->api = new SoapVar($api,SOAP_ENC_OBJECT,NULL,$this->wss_link,"api","wsse:api");
		$token->code = new SoapVar($code,XSD_STRING,NULL,$this->wss_link,"code","wsse:code");
		
		$security = new SoapVar(
        		new SoapVar($token, SOAP_ENC_OBJECT, NULL, $this->wss_link, 'Security',"wsse:Security"),
        SOAP_ENC_OBJECT, NULL, $this->wss_link, 'SoapSecurity', "wsse:SoapSecurity");
		
        parent::__construct($this->wss_link,'security',$security,true);
	}
}
